package com.atchangsha.system.service.impl;

import com.atchangsha.system.common.utils.Result;
import com.atchangsha.system.constant.LoginConstants;
import com.atchangsha.system.dto.LoginDto;
import com.atchangsha.system.service.AdminService;
import com.atchangsha.system.service.LoginService;
import com.atchangsha.system.service.WorkerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class LoginServiceImpl implements LoginService {
    @Resource
    private WorkerService workerService;

    @Resource
    private AdminService adminService;

    @Override
    public Result login(LoginDto loginDto) {
        int flag = loginDto.getFlag();
        String username = loginDto.getUsername();
        String password = loginDto.getPassword();
        if (flag == 1) {
            //员工登录
            return workerService.login(username, password);
        } else if (flag == 2) {
            //管理员登录
            return adminService.login(username,password);
        } else {
            //错误登录标志
            return Result.fail(LoginConstants.LoginEnum.LOGIN_FLAG_ERROR);
        }

    }
}
